package com.example.schedule.log;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.schedule.R;
import com.example.schedule.db.Log;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

import org.litepal.LitePal;
import org.litepal.crud.LitePalSupport;

import java.util.List;

public class LogActivity extends AppCompatActivity {

    private Button mLogBack;
    private FloatingActionButton mLogAdd;
    private TextView mLogText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_log);

        initView();
        initEvent();
    }

    private void initEvent() {

        List<Log> logList = LitePal.findAll(Log.class);

        String s = "";
        for (Log l : logList){
            s = s+"   "+l.getLogWrite();
        }

        mLogText.setText(s);

        mLogBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        mLogAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(LogActivity.this , LogCreateActivity.class));
            }
        });
    }

    private void initView() {
        mLogAdd = findViewById(R.id.btn_log_add);
        mLogBack = findViewById(R.id.btn_log_back);
        mLogText = findViewById(R.id.log_tv);
    }
}